<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.name" clearable class="filter-item" style="width: 150px;" placeholder="菜单名" />
      <el-date-picker v-model="listQuery.startDate" class="filter-item" type="date" placeholder="开始日期"></el-date-picker>
      <el-date-picker v-model="listQuery.endDate" class="filter-item" type="date" placeholder="结束日期"></el-date-picker>
      <el-button class="filter-item" type="primary" plain icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table ref="table" v-loading="listLoading" :data="list" border stripe style="width: 100%;" height="740">
      <el-table-column label="账号" prop="account" width="120" align="center"></el-table-column>
      <el-table-column label="操作" prop="name" width="160" align="center"></el-table-column>
      <el-table-column label="IP" prop="ip" width="120" align="center"></el-table-column>
      <el-table-column label="系统" prop="os" width="80" align="center"></el-table-column>
      <el-table-column label="时间" prop="operate_dt" width="140" align="center"></el-table-column>
      <el-table-column label="参数" width="400" align="center">
        <template slot-scope="{row}">
          <span v-if="row.params.length < 60">{{ row.params }}</span>
          <el-popover v-else trigger="hover" placement="top">
            <p>{{ row.params }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ row.params | sliceFilter }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import waves from '@/directive/waves' // 实现点击波浪纹
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { getOperateLogList } from '@/api/ops'
export default {
  name: 'OperateLog',
  components: { Pagination },
  directives: { waves },
  filters: {
    sliceFilter(str) {
      return str.slice(0, 60)
    }
  },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 200,
        name: '',
        startDate: new Date(),
        endDate: new Date()
      }
    }
  },
  created() {
    this.getList()
  },

  methods: {
    async getList() {
      const query = this.listQuery
      this.listLoading = true
      const res = await getOperateLogList(query)
      this.listLoading = false
      this.list = res.data.items
      this.total = res.data.total
      this.$nextTick(() => {
        this.$refs.table.doLayout()
      })
    },
    handleFilter() {
      this.getList()
    }
  }
}
</script>
